import Vue from 'vue'
import Vuex from 'vuex'
// vuex持久化插件
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    carGoods:[], // 购物车商品
    checkGoods: [], // 待付款
    PaidGoods:[], // 已付款
    receiving:[], // 收货地址
    collect:[], // 收藏
    user:[], // 用户
    userInfo:[], // 用户信息
    footprint:[], // 足迹
  },
  getters:{
    getData(state){
      return state
    },
  },
  mutations: {
    // 加购
    addGoods(state,data){
      state.carGoods.push(data)
    },
    // 待付款
    checkGoodsFun(state,data){
      state.checkGoods = data
    },
    // 已付款
    PaidGoodsFun(state,data){
      state.PaidGoods.push(data)
    },
    test(state,index){
      state.carGoods[index].num += 1; 
    },
    // 删除商品
    delData(state,index){
      state.carGoods.splice(index,1)
    },
    
    // 添加收货地址
    addReceiving(state,data){
      state.receiving.push(data)
    },
    // 收藏
    collected(state,data){
      state.collect.push(data)
    },
    isCollected(state,data){
      state.collect = data
    },
    // 删除收藏
    delcollected(state,index){
      state.collect.splice(index,1)
    },
    // 注册
    adduser(state,data){
      state.user.push(data)
    },
    // 添加用户信息
    userInfoFun(state,data){
      state.userInfo = data
    },
    // 足迹
    footprintFun(state,data){
      state.footprint.push(data)
    },
    // 足迹去重
    isfootprintFun(state,data){
      state.footprint = data
    },
    delFootprintFun(state,index){
      state.footprint.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  },
  plugins:[createPersistedState({
    storage:window.sessionStorage
  })]
})

